﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace Zzva.ESB
{
    public class TSysBko
    {

        private static TSysBko mvarSysBko;
        private OleDbConnection mvarConnect;


        protected TSysBko(OleDbConnection pConnect)
        {
            try { mvarConnect = pConnect; }
            catch (Exception e) { throw e; }
            finally { }
        }



        public static TSysBko GetSystem()
        {
             try
             {
              if (mvarSysBko == null) { mvarSysBko = GetSysBko(); }

              return mvarSysBko;
             }

             catch (Exception e) { throw e; }
             finally { }

        }



        private static TSysBko GetSysBko()
        {
            string lConnectStr;
            OleDbConnection lConnect;
            TSysBko lSysBko;

            try
            {
                //!!!!!!!!!!!!!
                //достаем Connect из установок
                ////Connect = RegisterLokal.GetSetting("Common", "SysBuhuchConnect");
                //lConnectStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\srvsapr\BKO\database\basekomp.mdb;Jet OLEDB:Database Password=Cl254J";
                lConnectStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\srvsapr\BKO\database\basekomp.mdb";
                //lConnectStr = lConnectStr + "User ID=" + User + ";Password=" + Password + ";";

                lConnect = new OleDbConnection(lConnectStr);
                lConnect.Open();
                lSysBko = new TSysBko(lConnect);
                return lSysBko;
            }
            catch (Exception e) { throw e; }
            finally { }
        }





        public string TestGetNetNamePk(int Id)
        {
            try
            {
                OleDbCommand sql;
                DataTable rst;
                OleDbDataAdapter adp;
                DataRow row;
                string NetNamePk;


                sql = new OleDbCommand();
                sql.Connection = mvarConnect;


                //sql.CommandText = " SELECT DSE, DISP, NAIMDSE, RAZD"
                //                + " FROM DSE"
                //                + " WHERE  DSE_ID = " + Id;

                sql.CommandText = " SELECT NET_NAME"
                                + " FROM kompy"
                                + " WHERE ID = " + Id;


                adp = new OleDbDataAdapter();
                adp.SelectCommand = sql;

                rst = new DataTable();
                adp.Fill(rst);


                if (rst.Rows.Count == 1)
                {
                    row = rst.Rows[0];
                    NetNamePk = (string)row["NET_NAME"];
                }

                else { NetNamePk = "Нет ПК"; }

                return NetNamePk;

            }


            catch (Exception e) { throw e; }
            finally { }
        }







    }
}
